<?PHP
// vim: set expandtab tabstop=4 shiftwidth=4:
// +----------------------------------------------------------------------+
// | SAPID: XML Sapiens Engine Demonstrator                               |
// +----------------------------------------------------------------------+
// | Author:  Max Baryshnikov aka Mephius <mb@rg.by>, 	                  |
// | Dmitry Sheiko (http://cmsdevelopment.com)		 	                  |
// | Copyright (c) 2004 Max Baryshnikov                                   |
// | http://sapid.sourceforge.net	                                      |
// +----------------------------------------------------------------------+
// | This source file is free software; you can redistribute it and/or    |
// | modify it under the terms of the GNU Lesser General Public           |
// | License as published by the Free Software Foundation; either         |
// | version 2.1 of the License, or (at your option) any later version.   |
// |                                                                      |
// | This source file is distributed in the hope that it will be useful,  |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
// | Lesser General Public License for more details.                      |
// +----------------------------------------------------------------------+
// Release: 17.11.04 (dd/mm/yy)
// $Id: checknewversion.inc.php,v 1.2 2005/06/14 13:32:21 mephius Exp $

$vdb = new sapi_vdb();

// Get information about last version on local SAPID
$ver_archive = $vdb->get_data($root_path."usr/xml/vdb/release.xml");
if($ver_archive) { foreach($ver_archive as $curversion) {}}
unset($ver_archive);



$release = false;
$fd = @fopen ("http://sapid.sourceforge.net/release.xml", "r");
if($fd){
	while (!feof ($fd)) {
		$release .= fgets($fd, 4096);
	}
	fclose ($fd);
}

if($release) {
	$version = preg_replace("/^.*?<version>(.*?)<\/version>.*?$/is", "\\1", $release);
	if($version!=$curversion["VERSION"]) {
		// Save post data
		$_POST["post_action"] = "CHANGEROW";
		$_POST["row"]["version"] = $version;
		$_POST["row"]["info"] = preg_replace("/^.*?<info>(.*?)<\/info>.*?$/is", "\\1", $release);
		$_POST["row"]["link"] = preg_replace("/^.*?<link>(.*?)<\/link>.*?$/is", "\\1", $release);
		$_POST["row"]["download"] = preg_replace("/^.*?<download>(.*?)<\/download>.*?$/is", "\\1", $release);
		$vdb->save_data_row($root_path."usr/xml/vdb/release.xml", false, false);
		echo "<script>\nwindow.open('".$http_path."usr/system/remind.php', 'remind', 'width=400, height=250, status=no,toolbar=no,menubar=no, scrollbars=no, resizable=no');\n</script>";
	}
}

?>